/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facades;

import entities.FacturaMultimarca;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author damfercer
 */
@Stateless
public class FacturaMultimarcaFacade extends AbstractFacade<FacturaMultimarca> {
    @PersistenceContext(unitName = "CorporatePU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public FacturaMultimarcaFacade() {
        super(FacturaMultimarca.class);
    }
    
    public Integer getIdentificador(){
        Integer identificador=1;
        FacturaMultimarca ultimo=getUltimaFacturaMultimarca();
        if(ultimo!=null){
            identificador=ultimo.getIdentificador()+1;
        }
        return identificador;
    }
    
    public FacturaMultimarca getUltimaFacturaMultimarca(){
        FacturaMultimarca ultimo=null;
        Query q=em.createNamedQuery("FacturaMultimarca.findLastFactura", FacturaMultimarca.class);
        q.setMaxResults(1);
        List<FacturaMultimarca> facturas=q.getResultList();
        if(!facturas.isEmpty()){
           ultimo=facturas.iterator().next(); 
        }
        return ultimo;
    }
    
}
